home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / ucsd / joe-ham
Internet Message Format  |  1996-10-25  |  9KB

  1. Return-Path: bind-request@uunet.uu.net
  2. Received: by cognition.pa.dec.com; id AA20768; Thu, 6 May 93 22:31:27 -0700
  3. Received: by inet-gw-2.pa.dec.com; id AA08078; Thu, 6 May 93 22:30:39 -0700
  4. Received: by rodan.UU.NET (5.61/UUNET-mail-drop)
  5.     id AA10465; Fri, 7 May 93 01:22:48 -0400
  6. Received: from relay1.UU.NET by rodan.UU.NET with SMTP 
  7.     (5.61/UUNET-mail-drop) id AA10461; Fri, 7 May 93 01:22:41 -0400
  8. Received: from inet-gw-1.pa.dec.com by relay1.UU.NET with SMTP 
  9.     (5.61/UUNET-internet-primary) id AA26744; Fri, 7 May 93 01:22:16 -0400
  10. Received: by inet-gw-1.pa.dec.com; id AA23315; Thu, 6 May 93 22:19:41 -0700
  11. Received: from ucsd.edu (ucsd.edu [128.54.16.1]) by vangogh.CS.Berkeley.EDU (ALPHA-6.55/6.25) id WAA29603; Thu, 6 May 1993 22:17:58 -0700
  12. Received: by ucsd.edu; id AA23528
  13.     sendmail 5.67/UCSD-2.2-sun
  14.     Thu, 6 May 93 22:18:06 -0700 for bind@vangogh.CS.Berkeley.EDU
  15. Date: Thu, 6 May 93 22:18:06 -0700
  16. From: brian@UCSD.EDU (Brian Kantor)
  17. Message-Id: <9305070518.AA23528@ucsd.edu>
  18. To: bind@vangogh.CS.Berkeley.EDU, sra@epilogue.com
  19. Subject: Re:  wish list
  20.  
  21. The AMPR.ORG domain is maintained by a mail robot which updates the zone
  22. files through a simple unique-key database.  Maintenance of the entries
  23. is split among more than 150 "coordinators" in more than 140 regions of
  24. the world (more than 50 countries), with more than 15,000 entries in the
  25. zone file.
  26.  
  27. It's simple stupid code, and people futz it up occasionally, but it works.
  28. Sure, I have to go through the database every few weeks and clean out
  29. the stupidities, but without the robot, I'd never have the time to maintain
  30. it by hand!
  31.  
  32. These tools are included below primarily as inspiration; I'd hate to inflict
  33. this Joe-code (I hacked it up in one weekend) on anyone who would run it as is.
  34.     - Brian
  35.  
  36. ::::::::::::::
  37. /usr/ham/Makefile
  38. ::::::::::::::
  39. all: ham.org hamhosts hamaddr ham.serial
  40.  
  41. ham.data: ham.pag dbtofile
  42.     dbtofile ham | sort -u > ham.data
  43.     chmod 664 ham.data
  44.     /usr/etc/chown nobody.ham ham.data
  45.  
  46. ham.org:    ham.head ham.rev.head ham.data ham.serial
  47.     cat ham.head ham.data > ham.org
  48.     cat ham.rev.head > ham.org.rev
  49.     fgrep '44.' ham.data | awk -f rev.awk >> ham.org.rev
  50.     cp ham.org /usr/spool/ftp/hamradio/ham.org
  51.     cp ham.org.rev /usr/spool/ftp/hamradio/ham.org.rev
  52.     chmod 444 /usr/spool/ftp/hamradio/ham.org
  53.     chmod 444 /usr/spool/ftp/hamradio/ham.org.rev
  54.     /usr/etc/chown nobody.ham /usr/spool/ftp/hamradio/ham.org
  55.     /usr/etc/chown nobody.ham /usr/spool/ftp/hamradio/ham.org.rev
  56.  
  57. hamhosts: ham.data
  58.     awk -f hosts.awk < ham.data > hamhosts
  59.     sort -nt. +1 -2 +2 -3 +3 -4 hamhosts -o hamhosts
  60.     cp hamhosts /usr/spool/ftp/hamradio/hamhosts
  61.     chmod 644 /usr/spool/ftp/hamradio/hamhosts
  62.     /usr/etc/chown nobody.ham /usr/spool/ftp/hamradio/hamhosts
  63.  
  64. ham.serial:    ham.data serial newserial
  65.     serial > ham.serial
  66.     newserial
  67.  
  68. serial:    serial.c
  69.     cc serial.c -O -o serial
  70. ::::::::::::::
  71. /usr/ham/hosts.awk
  72. ::::::::::::::
  73. /^#/        {print ""; print $0; h = "AaBbCc";next}
  74.  
  75. /IN    A/    {h = $1; 
  76.             printf("\n%s\t%s",$4,$1)
  77.             next}
  78.  
  79. $3 == "CNAME" && $4 == h    {printf " %s",$1}
  80.  
  81. END    {printf "\n"}
  82. ::::::::::::::
  83. /usr/ham/rev.awk
  84. ::::::::::::::
  85. /IN    A    44/    { 
  86. split($1, h, " "); 
  87.  
  88. split($4, a, ".");
  89. if (a[1] == "" || a[2] == "" || a[3] == "")
  90.     next;
  91.  
  92. if ( last4 != $4 ) {
  93.     printf "%s.%s.%s\tIN\tPTR\t%s.ampr.org.\n", a[4],a[3],a[2],h[1]
  94.     last4 = $4
  95.     }
  96. }
  97. ::::::::::::::
  98. /usr/ham/hamaddr.c
  99. ::::::::::::::
  100. #include <stdio.h>
  101. #include <ndbm.h>
  102. #include <strings.h>
  103. #include <ctype.h>
  104. #include <sys/file.h>
  105.  
  106. char buf[BUFSIZ];
  107. char dat[6][128];
  108. char from[BUFSIZ];
  109. char keybuf[256];
  110. char valbuf[256];
  111.  
  112. FILE *mailer;
  113.  
  114. #define sendmail "/usr/lib/sendmail -oi -t"
  115. #define DB    "/usr/ham/ham"
  116.  
  117. DBM *db;
  118. datum key, val;
  119.  
  120. main()
  121. {
  122. int nf;
  123. int lc = 0;
  124. int i;
  125. char *c;
  126. int hdr = 0;
  127.  
  128. mailer = popen(sendmail, "w");
  129. if (mailer == NULL)
  130.     {
  131.     perror(sendmail);
  132.     exit(-1);
  133.     }
  134.  
  135. db = dbm_open(DB, O_RDWR, 0666);
  136. if (db == NULL)
  137.     {
  138.     perror(DB);
  139.     exit(1);
  140.     }
  141.  
  142. while(fgets(buf, sizeof buf, stdin))
  143.     {
  144.     if ( (c = index(buf,'\n')) != NULL)
  145.         *c = 0;
  146.     
  147.     if (strlen(buf) < 1)
  148.         {
  149.         hdr++;
  150.         continue;
  151.         }
  152.     
  153.     if (hdr == 0  && !strncmp(buf, "From:", 5))
  154.         {
  155.         fprintf(mailer, "From: ham-request@ucsd.edu\n");
  156.         fprintf(mailer, "To: %s\n", &buf[5]);
  157.         printf("------->To: %s\n", &buf[6]);
  158.         fprintf(mailer, "Subject: address update rec'd\n");
  159.         fprintf(mailer,"\n\n--- begin ---\n");
  160.         continue;
  161.         }
  162.  
  163.     if (hdr == 0)
  164.         continue;
  165.  
  166.     fprintf(mailer,"> %s\n", buf);
  167.  
  168.     if ( (c = index(buf,'#')) != NULL)
  169.         *c = 0;
  170.     if ( (c = index(buf,';')) != NULL)
  171.         *c = 0;
  172.     if ( (c = index(buf,'\r')) != NULL)
  173.         *c = 0;
  174.     c = buf;
  175.     while (*c)
  176.         {
  177.         if (isupper(*c))
  178.             *c = tolower(*c);
  179.         c++;
  180.         }
  181.  
  182.     nf = sscanf(buf, "%s %s %s %s %s",
  183.         dat[1], dat[2], dat[3], dat[4], dat[5]);
  184.     
  185.     if (nf < 2)
  186.         {
  187.         fprintf(mailer,"---> ignored\n");
  188.         continue;
  189.         }
  190.  
  191.     if (dat[1][strlen(dat[1])-1] == '.')
  192.         {
  193.         fprintf(mailer,"---> error: trailing period in field 1\n");
  194.         continue;
  195.         }
  196.  
  197.     if (dat[2][strlen(dat[2])-1] == '.')
  198.         {
  199.         fprintf(mailer,"---> error: trailing period in field 2\n");
  200.         continue;
  201.         }
  202.     
  203.     if (!strncmp(dat[1],"44.",3))    /* must be host table fmt */
  204.         {
  205.         lc++;
  206.         fprintf(mailer,"%d ---> ADD/CHANGE: %s\tIN\tA\t%s\n",
  207.                 lc, dat[2], dat[1]);
  208.         sprintf(keybuf,"A-%s", dat[2]);
  209.         key.dptr = keybuf;
  210.         key.dsize = strlen(key.dptr) + 1;
  211.         sprintf(valbuf, "%s\tIN\tA\t%s\n",
  212.                 dat[2], dat[1]);
  213.         val.dptr = valbuf;
  214.         val.dsize = strlen(val.dptr) + 1;
  215.         dbm_store(db, key, val, DBM_REPLACE);
  216.         continue;
  217.         }
  218.     
  219.     if (nf == 4 && !strcmp(dat[2],"in") && !strcmp(dat[3],"a"))
  220.         {
  221.         lc++;
  222.         sprintf(keybuf,"A-%s", dat[1]);
  223.         key.dptr = keybuf;
  224.         key.dsize = strlen(key.dptr) + 1;
  225.         sprintf(valbuf, "%s\tIN\tA\t%s\n", 
  226.                 dat[1], dat[4]);
  227.         val.dptr = valbuf;
  228.         val.dsize = strlen(val.dptr) + 1;
  229.         if (strcmp(dat[4], "delete"))
  230.             {
  231.             dbm_store(db, key, val, DBM_REPLACE);
  232.             fprintf(mailer,"%d ---> ADD/CHANGE: %s\tIN\tA\t%s\n", 
  233.                 lc, dat[1], dat[4]);
  234.             }
  235.         else
  236.             {
  237.             dbm_delete(db,key);
  238.             fprintf(mailer,"%d ---> DELETED: %s\tIN\tA\t%s\n", 
  239.                 lc, dat[1], dat[4]);
  240.             }
  241.         continue;
  242.         }
  243.     
  244.     if (nf == 4 && !strcmp(dat[2],"in") && !strcmp(dat[3],"cname"))
  245.         {
  246.         lc++;
  247.         fprintf(mailer,"%d:\t%s\tIN\tCNAME\t%s\n", 
  248.                 lc, dat[1], dat[4]);
  249.         sprintf(keybuf,"C-%s", dat[1]);
  250.         key.dptr = keybuf;
  251.         key.dsize = strlen(key.dptr) + 1;
  252.         sprintf(valbuf, "%s\tIN\tCNAME\t%s\n", 
  253.                 dat[1], dat[4]);
  254.         val.dptr = valbuf;
  255.         val.dsize = strlen(val.dptr) + 1;
  256.         if (strcmp(dat[4], "delete"))
  257.             {
  258.             dbm_store(db, key, val, DBM_REPLACE);
  259.             fprintf(mailer,"%d ---> ADD/CHANGE: %s\tIN\tA\t%s\n", 
  260.                 lc, dat[1], dat[4]);
  261.             }
  262.         else
  263.             {
  264.             dbm_delete(db,key);
  265.             fprintf(mailer,"%d ---> DELETED: %s\tIN\tA\t%s\n", 
  266.                 lc, dat[1], dat[4]);
  267.             }
  268.         continue;
  269.         }
  270.     
  271.     if (nf == 5 && !strcmp(dat[2],"in") && !strcmp(dat[3],"mx")
  272.     && isdigit(dat[4][0]))
  273.         {
  274.         lc++;
  275.         fprintf(mailer,"%d:\t%s\tIN\tMX %s\t%s\n", 
  276.                 lc, dat[1], dat[4], dat[5]);
  277.         sprintf(keybuf,"M%s-%s", dat[4], dat[1]);
  278.         key.dptr = keybuf;
  279.         key.dsize = strlen(key.dptr) + 1;
  280.         sprintf(valbuf, "%s\tIN\tMX %s\t%s\n", 
  281.                 dat[1], dat[4], dat[5]);
  282.         val.dptr = valbuf;
  283.         val.dsize = strlen(val.dptr) + 1;
  284.         if (strcmp(dat[5], "delete"))
  285.             {
  286.             dbm_store(db, key, val, DBM_REPLACE);
  287.             fprintf(mailer,"%d ---> ADD/CHANGE: %s\tIN\tMX %s\t%s\n", 
  288.                 lc, dat[1], dat[4], dat[5]);
  289.             }
  290.         else
  291.             {
  292.             dbm_delete(db,key);
  293.             fprintf(mailer,"%d ---> DELETED: %s\tIN\tMX %s\t%s\n", 
  294.                 lc, dat[1], dat[4], dat[5]);
  295.             }
  296.         continue;
  297.         }
  298.     
  299.     fprintf(mailer,"---> skipped: record format error\n");
  300.     }
  301.  
  302. fprintf(mailer,"--- end ---\n");
  303. fflush(mailer);
  304. pclose(mailer);
  305. dbm_close(db);
  306. exit(0);
  307. }
  308. ::::::::::::::
  309. /usr/ham/dbtofile.c
  310. ::::::::::::::
  311. /*
  312.  * dumps DBM database contents to stdout
  313.  */
  314.  
  315. #include <stdio.h>
  316. #include <ndbm.h>
  317. #include <sys/file.h>
  318.  
  319. char buf[BUFSIZ];
  320.  
  321. DBM *db;
  322. datum key, val;
  323.  
  324. main(argc,argv)
  325. int argc;
  326. char **argv;
  327.     {
  328.     if (argc != 2)
  329.         {
  330.         fprintf(stderr,"Usage: dbtofile db \n");
  331.         exit(1);
  332.         }
  333.  
  334.     if ((db = dbm_open(argv[1], O_RDONLY, 0)) < 0)
  335.         {
  336.         perror(argv[1]);
  337.         exit(1);
  338.         }
  339.  
  340.     for (key = dbm_firstkey(db); key.dptr != NULL;
  341.                 key = dbm_nextkey(db))
  342.         {
  343.         val = dbm_fetch(db, key);
  344.         puts(val.dptr);
  345.         }
  346.     }
  347. ::::::::::::::
  348. /usr/ham/serial.c
  349. ::::::::::::::
  350. #include <stdio.h>
  351. #include <sys/time.h>
  352.  
  353. main()
  354.     {
  355.     struct tm *tm;
  356.     struct timeval tv;
  357.     struct timezone tz;
  358.  
  359.     gettimeofday(&tv,&tz);
  360.  
  361.     tm = gmtime(&tv.tv_sec);
  362.  
  363.     printf("\t\t\t\t%02d%02d%02d%02d\t; Serial\n",
  364.         tm->tm_year, (tm->tm_mon + 1), tm->tm_mday, tm->tm_hour);
  365.     exit(0);
  366.     }
  367. ::::::::::::::
  368. /usr/ham/newserial
  369. ::::::::::::::
  370. #!/bin/sh
  371. for f in \
  372.     ham.head \
  373.     ham.rev.head \
  374.         ; do
  375. ex $f << EOF > /dev/null
  376. /Serial/
  377. d
  378. -
  379. r ham.serial
  380. w
  381. q
  382. EOF
  383. echo $f 'updated' ;
  384. done ;
  385. exit 0
  386.